/*
 * @Author: 晟松
 * @Date: 2021-12-07 20:18:38
 * @LastEditors: 晟松
 * @LastEditTime: 2021-12-07 22:28:48
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\db\relationCreate.js
 * @Description: 方便的创建model之间的关联和进行保存
 */
/**
 * @description: 一对一关系的多次创建
 * @param {*} modelMap 最关键的sequelize.define的返回
 * @param {*} relationArr
 * @param {*} relationName 需要多次关联的那一个modelName
 * @return {*}
 */

// modelMap['login'].student = modelMap['login'].hasOne(modelMap['student'])
export function oneToOneReletion(modelMap, relationArr, relationName) {
    relationArr.forEach((relation) => {
        modelMap[relationName][relation] = modelMap[relationName].hasOne(modelMap[relation]);
        modelMap[relation][relationName] = modelMap[relation].belongsTo(
            modelMap[relationName]
        );
    });
}
/**
 * @description: 一对多关联
 * @param {*} modelMap
 * @param {*} one 一对多中的一
 * @param {*} many 一对多中的多
 * @return {*}
 */
export function oneToManyReletion(modelMap, one, many) {
    modelMap[one][many] = modelMap[one].hasMany(modelMap[many]);
    modelMap[many][one] = modelMap[many].belongsTo(modelMap[one]);
}
